<?php

/**
 * @author Dingo
 */
class Form_Uzytkownik {

    public static function generuj($user, $action, $grupy) {
        $formularz = '<div class="form">';
        $Config = array(
            // Default fields size
            'size' => 35,
            // Default fields error css
            'css_error' => 'fields_error',
            'template_open' => '<div class="form_row">',
            'template_label' => '<label>|LABEL|</label>',
            'template_field' => '|FIELD|',
            'template_error' => '<BR><font class="error">- |ERROR|</font>',
            'template_close' => '</div>',
            'template_line' => "\n",
            'template_field_one' => '<div class="form_row">|LABEL||FIELD|</div>'
        );


        $Form = & new Form_AuriumForm($Config);
        $formularz .= $Form->OpenForm(array('m' => 'p',
                    'action' => $action));

        $id = array(
            'type' => 'hidden',
            'name' => 'id',
            'value' => isset($user['id']) ? $user['id'] : null);

        $login = array('label' => 'Login:',
            'type' => 'text',
            'name' => 'login',
            'value' => htmlspecialchars(isset($_POST['login']) ? $_POST['login'] : $user['login']));

        $mail = array(
            'label' => 'Mail:',
            'type' => 'text',
            'name' => 'mail',
            'value' => htmlspecialchars(isset($_POST['mail']) ? $_POST['mail'] : $user['mail']));

        $grupa = array(
            'label' => 'Grupa:',
            'type' => 'selectbox',
            'name' => 'id_grupa',
            'items' => $grupy,
            'selected' => isset($_POST['id_grupa']) ? $_POST['id_grupa'] : $user['id_grupa'],
        );
        
        $status = array(
            'label' => 'Status:',
            'type' => 'selectbox',
            'name' => 'status',
            'items' => array('1' => 'Aktywny', '2' => 'Nieaktywny', '3' => 'Zbanowany', '0' => 'Usunięty'),
            'selected' => isset($_POST['status']) ? $_POST['status'] : isset ($user['status']) ? $user['status'] : 1,
        );

        $przyciski = array(
            'type' => 'button',
            'subtype' => array('submit', 'button'),
            'value' => array('Wyślij', 'Anuluj'),
            'extras' => array('', 'onClick="window.location = \'/cms/uzytkownicy/\';"'),
            'alone' => true
        );

        $Form->SetData(array($login, $mail, $grupa, $status, $id));
        $formularz .= $Form->ShowFields();
        $formularz .= '<div class="form_row"><label>Hasło:</label>Hasło zostanie wygenerowane i wysłane na maila!</div>';
        $formularz .= $Form->OneField($przyciski);
        $formularz .= $Form->CloseForm();
        $formularz .= '</div>';
        return $formularz;
    }

}

?>
